Namespace DataStream
    <Serializable(), ObfuscationAttribute(Exclude:=True, ApplyToMembers:=True)> _
    Public Class StreamDictionary
        Inherits DictionaryBase

        Private mCurrentIndex As UShort = 0

        Public Sub New(Optional ByVal base As UShort = 1)
            ' mCurrentIndex = base
        End Sub
        ''' <summary>
        ''' Gets or Sets the value for the given Index
        ''' </summary>
        ''' <param name="index"></param>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Default Public Property Item(ByVal index As UShort) As String
            Get
                Return CType(MyBase.Dictionary(index), String)
            End Get
            Set(ByVal value As String)
                Dictionary(index) = value
            End Set
        End Property
        ''' <summary>
        ''' Gets the index from the key (string)
        ''' </summary>
        ''' <param name="key"></param>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Default Public ReadOnly Property Item(ByVal key As String) As UShort
            Get
                Dim col As New ArrayList(Me.Values)
                Return col.Count - col.IndexOf(key) - 1


                'Return Me.Dictionary.Item(key)


                'Dim values As New ArrayList(MyBase.Dictionary.Keys)
                'Dim idx As Integer = values.IndexOf(key)
                'If idx >= 0 Then
                '    Return values.IndexOf(key)
                'Else
                '    Return 0
                'End If
            End Get
        End Property

        Public ReadOnly Property Keys() As ICollection
            Get
                Return Dictionary.Keys
            End Get
        End Property

        Public ReadOnly Property Values() As ICollection
            Get
                Return Dictionary.Values
            End Get
        End Property

        ''' <summary>
        ''' using this function is Very risky.. you have been warned
        ''' </summary>
        ''' <param name="key"></param>
        ''' <param name="value"></param>
        ''' <remarks></remarks>
        Public Sub Add(ByVal key As String, ByVal value As UShort)
            Dictionary.Add(key, value)
        End Sub

        ''' <summary>
        ''' This function either adds the the key or retrieves it if it has
        ''' already been added in
        ''' </summary>
        ''' <param name="Key"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function Add(ByVal key As String) As UShort
            Dim col As New ArrayList(Me.Values)
            If col.Contains(key) Then
                'Return Me.Dictionary.Item(key)
                Return col.Count - col.IndexOf(key) - 1
            Else
                Me.Dictionary.Add(mCurrentIndex, key)
                mCurrentIndex += 1
                Return mCurrentIndex - 1
            End If
        End Function

        Public Function Contains(ByVal key As String) As Boolean
            Dim col As New ArrayList(Me.Values)
            If col.Contains(key) Then
                Return True
            Else
                Return False
            End If
            'If Dictionary.Item(key) Is Nothing Then
            '    Return False
            'Else
            '    Return False
            'End If
        End Function

    End Class
End Namespace


